package com.example.demo.web.controller;

import com.example.demo.bean.BaseConfig;
import com.example.demo.service.IBaseConfigService;
import com.example.demo.utils.Message;
import com.example.demo.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/baseConfig")
@Validated
public class BaseConfigController {
    @Autowired
    private IBaseConfigService baseConfigService;

    @GetMapping("query")
    public Message query(Long id) {
        List<BaseConfig> list = baseConfigService.query(id);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BaseConfig baseConfig) {
        baseConfigService.saveOrUpdate(baseConfig);
        return MessageUtil.success("保存成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="用户编号",required=true,paramType ="query")
    })
    public Message deleteById(@NotNull long id) {
        baseConfigService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
